package com.dqy.twserver.server.handle.ehandle.mutil;

import com.dqy.twserver.server.dto.GameDto;
import com.dqy.twserver.server.handle.ehandle.GameEventCreateRoomHandle;
import com.dqy.twserver.server.handle.ehandle.GameEventHandle;
import com.dqy.twserver.server.support.Player;
import com.dqy.twserver.server.support.SupportMap;
import io.netty.channel.socket.nio.NioSocketChannel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Map;

public class GameEventMutilRegistHandle implements GameEventHandle {
    static Logger logger = LoggerFactory.getLogger(GameEventMutilRegistHandle.class);
    @Override
    public void handle(GameDto req, NioSocketChannel channel) throws Exception {
        logger.info("[GameEventMutilRegistHandle] start");
        GameDto resp=new GameDto();

        String playerName = req.getPlayerName();
        Map<String, Player> playerMap = SupportMap.playerMap;
        Player playerConnect = playerMap.get(playerName);
        if(playerConnect==null){
            resp.setInfo("错误的请求，找不到该玩家的连接资源");
            resp.setSts(400);
            channel.writeAndFlush(resp);
            logger.info("[GameEventMutilRegistHandle] 错误的请求，找不到该玩家的连接资源 name={}",playerName);
            return;
        }
        playerConnect.setMutilSocktChannel(channel);
        logger.info("广播socket注册完毕");
        resp.setSts(200);
        resp.setInfo("-200");
        channel.writeAndFlush(resp);
        logger.info("[GameEventMutilRegistHandle] end");

    }
}
